package com.zhihao.takeaway.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhihao.takeaway.entity.Chat;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChatMapper extends BaseMapper<Chat> {

    @Select("select distinct * from  ${tableName} where from_account = #{toAccount} or to_account = #{toAccount} order by time asc")
    List<Chat> selectEncord(@Param("tableName") String tableName,@Param("fromAccount") String fromAccount,@Param("toAccount") String toAccount);

    @Insert("insert into ${tableName}(id,from_account,to_account,message,time) values(#{uuid},#{fromAccount},#{toAccount},#{message},#{date})")
    void saveEncord(@Param("tableName") String tableName,@Param("fromAccount") String fromAccount,@Param("toAccount") String toAccount,@Param("message") String message,@Param("date") String date,@Param("uuid") String uuid);
}
